
const mysql = require('mysql2/promise');
//const mysql = require('mysql');
// 云函数入口函数
exports.main = async (event, context) => {
  let connection;
  try {
    // 创建 MySQL 连接
    connection = await mysql.createConnection({
      host: 'sh-cynosdbmysql-grp-2gf1ewak.sql.tencentcdb.com',
      port: 28451,
      user: 'root',
      password: 'Aa123321',
      database: 'project_lm',
      waitForConnections: true,
      connectionLimit: 10,
      queueLimit: 0
    });

    // 执行 SQL 查询
    const [rows] = await connection.execute(event.command);
    return { data: rows };

  } catch (error) {
    console.error('Error:', error); // 输出错误信息
    return { error: error.message }; // 返回错误信息给调用者
  } finally {
    if (connection) {
      await connection.end(); // 确保连接被关闭
    }
  }
};